﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="EditProperty.aspx.cs" Inherits="LizzabethBrownRealEstate.Views.Admin.EditProperty" %>
<%@ Import Namespace="LizzabethBrownRealEstate.Controllers" %>
<%@ Import Namespace="LizzabethBrownRealEstate.Models" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ScriptPlaceHolder" runat="server">
    <script type="text/javascript">
    
        function setFeatured(photoId, propertyId){
               $.getJSON("../Admin.ashx/SetFeaturedPhoto?photoId=" + photoId + "&propertyId=" + propertyId);
               var images = document.getElementsByTagName("img");
                for (var i=0; i<images.length; i++){
                    if (images[i].className == "propFeatured"){
                        images[i].src = '../../Content/images/a_unchecked_.gif';
                    }
                }
                var sel = document.getElementById(photoId);
                sel.src = '../../Content/images/a_checked_.gif';
            }

            $(document).ready(function() {
                $('img.deleteButton').css('position', 'relative');
                $('img.deleteButton').css('left', -144);
                $('img.propFeatured').css('left', -15);
                if (navigator.appName == "Microsoft Internet Explorer") {
                    $('img.deleteButton').css('top', -100);
                    $('img.propFeatured').css('top', -106);
                } else {
                    $('img.deleteButton').css('top', -105);
                    $('img.propFeatured').css('top', -105);
                }

                jQuery().ajaxStart(function() {
                    $("#Progress").css('display', 'inline');
                });

                jQuery().ajaxStop(function() {
                    $("#Progress").css('display', 'none');
                });

                //VALIDATION//
                $("#frmProperty").validate({
                    errorClass: "invalid",
                    wrapper: "li",
                    rules: {
                        Bathrooms: { number: true },
                        Fireplaces: { number: true },
                        FullBaths: { number: true },
                        TotalSquareFeet: { number: true },
                        TotalLivingArea: { number: true },
                        Rooms: { number: true },
                        Frontage: { number: true },
                        Bedrooms: { number: true }
                    },

                    errorLabelContainer: "#frmPropertyErr",
                    messages: {
                        Bathrooms: "Bathrooms requires a valid number.",
                        Fireplaces: "Fireplaces requires a valid number.",
                        FullBaths: "Full Baths requires a valid number.",
                        TotalSquareFeet: "Total Square Feet requires a valid number.",
                        TotalLivingArea: "Total Living Area requires a valid number.",
                        Rooms: "Room requires a valid number.",
                        Frontage: "Frontage requires a valid number.",
                        Bedrooms: "Bedrooms requires a valid number."
                    }
                });
                $("input:checkbox").css("width", "20px");
                $("textarea").css("width", "300px");
            });      
        
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="StylePlaceHolder" runat="server">
    <style type="text/css">
        .deleteButton a { position: relative; border:none; }
        .deleteButton { position: relative; width:20px; height:20px; border:none; }  
        img.propPhoto{ position:relative; display:inline;  }  
        img.propFeatured { position: relative; width:20px; height:20px; border:none; display:inline; margin-left:-5px; margin-right: -10px; }    
        .invalid {border: dotted 1pt red; }
        input { width: 120px }
    </style>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
    <% LBRDataContext dc = new LBRDataContext();  %>
    <% RealEstateProperty p = dc.GetRealEstateProperty(int.Parse(ViewData["PropertyId"].ToString())); %>
    <% if (p == null) p = new RealEstateProperty(); %>
    <% object vals = new {propertyId = p.PropertyId };  %>
    <form method="post" id="frmProperty" enctype="multipart/form-data" action="<%=  Url.Action("SaveOrUpdateProperty", "Admin", vals ) %>" >
        
        <div class="contentDiv" style="margin-left:15%">
            <fieldset id="fldRegister" style="width:530px;display:block;">
                <legend>New Property</legend>
                <table width="100%">
                    <tr class="addPropertyRow">
                        <td class="addPropertyLabel"><label class="label" for="Location">Location:&nbsp;</label></td>
                        <td class="addPropertyField"><%= Html.DropDownList("Select..", "Location", new SelectList(dc.Locations, "LocationId", "Name", (p.Location != null) ? p.Location.LocationId : 1)) %></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr class="addPropertyRow">
                        <td class="addPropertyLabel"><label class="label" for="Bathrooms">#&nbsp;of&nbsp;Bathrooms:&nbsp;</label></td>
                        <td class="addPropertyField"><%= Html.TextBox("Bathrooms", p.Bathrooms) %></td>
                        <td class="addPropertyLabel"><label class="label" for="Fireplaces">#&nbsp;of&nbsp;Fireplaces:&nbsp;</label></td>
                        <td class="addPropertyField"><%= Html.TextBox("Fireplaces", p.Fireplaces) %></td>
                    </tr>
                    <tr class="addPropertyRow">
                        <td class="addPropertyLabel"><label class="label" for="FullBaths">#&nbsp;of&nbsp;Full&nbsp;Baths:&nbsp;</label></td>
                        <td class="addPropertyField"><%= Html.TextBox("FullBaths", p.FullBaths) %></td>
                        <td class="addPropertyLabel"><label class="label" for="Rooms">#&nbsp;of&nbsp;Rooms:&nbsp;</label></td>
                        <td class="addPropertyField"><%= Html.TextBox("Rooms", p.Rooms) %></td>
                    </tr>
                    <tr class="addPropertyRow">
                        <td class="addPropertyLabel"><label class="label" for="TotalLivingArea">Total Living Area:&nbsp;</label></td>
                        <td class="addPropertyField"><%= Html.TextBox("TotalLivingArea", p.TotalLivingArea) %></td>
                        <td class="addPropertyLabel"><label class="label" for="TotalSquareFeet">Total&nbsp;Square&nbsp;Feet:&nbsp;</label></td>    
                        <td class="addPropertyField"><%= Html.TextBox("TotalSquareFeet", p.TotalSquareFeet) %></td>                    
                    </tr>
                    <tr class="addPropertyRow">
                        <td class="addPropertyLabel"><label class="label" for="Garg">Has&nbsp;Garage?:&nbsp;</label></td>
                        <td class="addPropertyField"><%= Html.CheckBox("Garage", p.Garage.GetValueOrDefault())%></td>
                        <td class="addPropertyLabel"><label class="label" for="GargAttch">Garage&nbsp;Attached?:&nbsp;</label></td>
                        <td class="addPropertyField"><%= Html.CheckBox("GarageAttached", p.GarageAttached.GetValueOrDefault())%></td>
                    </tr>
                    <tr class="addPropertyRow">
                        <td class="addPropertyLabel"><label class="label" for="Hist">Is&nbsp;Historic:&nbsp;</label></td>
                        <td class="addPropertyField"><%= Html.CheckBox("Historic", p.Historic.GetValueOrDefault())%></td>
                        <td class="addPropertyLabel"><label class="label" for="MLSNumber">MLS&nbsp;Number:&nbsp;</label></td>
                        <td class="addPropertyField"><%= Html.TextBox("MLSNumber", p.MLSNumber) %></td>
                    </tr>
                    <tr class="addPropertyRow">
                        <td class="addPropertyLabel"><label class="label" for="Bsmnt">Has&nbsp;Basement?:&nbsp;</label></td>
                        <td class="addPropertyField"><%= Html.CheckBox("Basement", p.Basement.GetValueOrDefault())%></td>
                        <td class="addPropertyLabel"><label class="label" for="NewConst">New&nbsp;Contstruction?:&nbsp;</label></td>
                        <td class="addPropertyField"><%= Html.CheckBox("NewConstruction", p.NewConstruction.GetValueOrDefault())%></td>
                    </tr>
                    <tr class="addPropertyRow">
                        <td class="addPropertyLabel"><label class="label" for="Bedrooms">Bedrooms:&nbsp;</label></td>
                        <td class="addPropertyField"><%= Html.TextBox("Bedrooms", p.Bedrooms)%></td>
                        <td class="addPropertyLabel"><label class="label" for="Frontage">Total&nbsp;Frontage:&nbsp;</label></td>    
                        <td class="addPropertyField"><%= Html.TextBox("Frontage", p.Frontage)%></td>                    
                    </tr>
                    <tr class="addPropertyRow">
                        <td class="addPropertyLabel"><label class="label" for="Price">Price:&nbsp;</label></td>
                        <td class="addPropertyField"><label class="label">$</label><%= Html.TextBox("Price", p.Price) %></td>
                        <td class="addPropertyLabel"><label class="label" for="Ftur">Featured:&nbsp;</label></td>
                        <td class="addPropertyField"><%= Html.CheckBox("Feature", p.Feature) %></td>
                    </tr>
                    <tr class="addPropertyRow">
                        <td class="addPropertyLabel"><label class="label" for="Description">Description:&nbsp;</label></td>
                        <td colspan="3" class="addPropertyField"><%= Html.TextArea("Description", p.Description) %></td>
                    </tr>
                    <tr>
                        <td colspan="4"><div id="frmPropertyErr" class="ValidateErrorContainer"></div></td>
                    </tr>
                </table>
            </fieldset>
            <% if (p.PropertyId > 0)
               { %>
            <fieldset id="Fieldset1" style="width:530px;display:block; ">
                <legend>Property Photos</legend>
                    <div class="dvPhotContainer" style="width:530px; height:140px; overflow:auto; position:relative; margin-top:0px; text-align:left">
                        <% foreach (Photo f in p.Photos.AsEnumerable<Photo>().Where<Photo>(foto => foto.Deleted == false))
                           { %>
                        <div style="display:inline;">
                            <% object pId = new {photoId = f.PhotoId, propertyId = p.PropertyId };  %>
                                <img class="propPhoto" src='../Repository/<%= f.FileName %>' alt="" height="120" width="130" style="margin-left:0px; margin-bottom:5px" />
                                <% if (f.Featured)
                                   { %>
                                    <a  class="setFeatured" href="javascript:setFeatured('<%=f.PhotoId %>','<%=p.PropertyId %>')"  photoId='<%=f.PhotoId %>' propId='<%=p.PropertyId %>'><img id='<%=f.PhotoId %>' title="Featured Property Photo" src='../../Content/images/a_checked_.gif'  alt="Featured property" class="propFeatured" /></a>
                                <%}
                                   else
                                   { %>
                                   <a class="setUnFeatured" href="javascript:setFeatured('<%=f.PhotoId %>','<%=p.PropertyId %>')" photoId='<%=f.PhotoId %>' propId='<%=p.PropertyId %>'><img id='<%=f.PhotoId %>' title="Featured Property Photo" src='../../Content/images/a_unchecked_.gif' alt="Featured property" class="propFeatured" /></a>
                                <%} %>
                                <a onclick="return confirm('Delete this photo?');" href='<%=Url.Action("DeletePhoto", "Admin", pId ) %>' class="deleteButton"><img title="delete" class="deleteButton" src='../../Content/images/delete.png' alt="delete" /></a>
                        </div>
                        <% } %>
                    </div>
                    <% object pvals = new { propertyId = p.PropertyId, _class = "linktableButton" }; %>
                    <div style="margin-top:10px;" class="linktableButton"><%=  Html.ActionLink("Add a photo...", "AddPhoto", "Admin", pvals)%></div>                        
            </fieldset>
            
            <%} %>
            <div style="width:330px;display:inline;">
                <%= Html.Hidden("UpdateId", p.PropertyId) %>
                <input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" style="width: 80px" />
                <button onclick="window.location='../Admin.ashx/PropertyList'; return false;">Cancel</button>
            </div>
            <div style="display:inline"><img id="Progress" src="../Content/Images/progress_bar.gif" style="display:none;" alt="Please wait..." /></div>
            
        </div>
    </form>
</asp:Content>
